package com.guocloud.medimind.controller;

import com.guocloud.medimind.adviser.MyLoggerAdvisor;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/heart")
@Tag(name = "项目健康心跳检测", description = "提供智能医疗项目的正常运行检测")
public class HealthyController {

    @Autowired
    @Qualifier("ollamaChatModel")
    private ChatModel ollaChatModel;

    @Autowired
    private ChatClient chatClient;

    @PostMapping("chat")
    @Operation(summary = "测试项目")
    public String testChat(String chatId) {
        ChatResponse chatResponse = chatClient.prompt()
                .user("你好")
                .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, chatId))
                .advisors(new MyLoggerAdvisor())
                .call()
                .chatResponse();

        return chatResponse.getResult().getOutput().getText();

    }

    @PostMapping("/test")
    @Operation(summary = "测试项目是否正常")
    public String test() {
        AssistantMessage output = ollaChatModel.call(new Prompt("你好"))
                .getResult()
                .getOutput();
        return output.getText();
    }

    @PostMapping("/healthy")
    public String healthy() {
        return "healthy";
    }
    
    @GetMapping("/healthy")
    @Operation(summary = "健康检查GET方法")
    public String healthyGet() {
        return "healthy";
    }
}
